< previous page page_176 next page >

Page 176
To start, set the Required property to True for the following controls:
· CompanyName
· Addr1
· City
· State/Province
Next, you need to add message code in the error event of the required fields. Listing 5.55 shows the code to place in the various events.
Type.gifListing 5.55. Coding the error messages for the required fields.
Private Sub vxtAddr1_RequiredError()
    '
    MsgBox "This is a required field", vbExclamation, vxtAddr1.DataField
    '
End Sub

Private Sub vxtCity_RequiredError()
    '
    MsgBox "This is a required field", vbExclamation, vxtCity.DataField
    '
End Sub

Private Sub vxtCompanyName_RequiredError()
    '
    MsgBox "This is a required field", vbExclamation, vxtCompanyName.DataField
    '
End Sub

Private Sub vxtStateProv_RequiredError()
    '
    MsgBox "This is a required field", vbExclamation, vxtStateProv.DataField
    '
End Sub
Now you need to add the code that checks for conditional input. The best place to put the conditional code is in a single ValidateForm method. This covers all the field- and form-level validation in one pass. Listing 5.56 shows the ValidateForm method for this form. Create a new Sub called ValidateForm and enter the code from listing 5.56.
Type.gifListing 5.56. Performing validation checks.
Private Sub ValidateForm()
    '
    ' check required fields
    vxtCompanyName.CheckRequired

 
< previous page page_176 next page >

If you like this book, buy it!